-- PaladinFoyer
-- Created by huanghr Mar/4/2016
-- 圣骑士休息室

-- 初始化
function initPaladinFoyer(self)
    self.item:removeAllChildren();

    local class = self.gridData.class;
    local buildingInfo = BuildingBonusM.queryBuildingView(class);

    if not buildingInfo then
        error("获取不到建筑查看配置，元素类型：" .. class);
        return;
    end

    local function doEvent()
        DungeonActionM.go("do_building_bonus", self.gridData:getPos());
    end

    local function rest()
        playPaladinEffect(self.node);
        -- 休息后的奖励
        performWithDelay(self, doEvent, 3.5);
    end

    local function onClicked(sender, eventType)
        if eventType == ccui.TouchEventType.began then
            if self.gridData.state == GRID_STATE_DISABLE then
                -- 已经失效，不处理
                return;
            end

            -- 更新建筑访问
            AudioM.playFx("ui_open1");
            self:updateBuildingVisit();

            if not DungeonM.isAllMonsterDead() then
                -- 需要击杀所有怪物方可拾取
                self:openBuildingView(nil, -20, buildingInfo["dialog2"], getLocStr("btn_text_leave"));
                return;
            end

            -- 打开建筑查看界面
            self:openBuildingView(rest);
        end
    end

    -- 建筑图标
    local iconPath = getLevelItemIconPath(buildingInfo["icon"]);

    self.icon = ccui.ImageView:create(iconPath);
    self.icon:setTouchEnabled(true);
    self.icon:addTouchEventListener(onClicked);
    self.item:addChild(self.icon);
    self.iconPath = iconPath;

    -- 整体往上偏移一点
    self.item:setPositionY(20);
end
